(function ()
{
    "use strict";

    function parseToLowerUpperMix(textForProcessing)
    {
        var result = [];
        var commands = [];

        for (var i = 0; i < textForProcessing.length; i++)
        {
            if (textForProcessing[i] === '<')
            {
                if (textForProcessing[i + 1] === 'l')
                {
                    commands.push('l');
                    i += 8;
                    continue;
                }
                else if (textForProcessing[i + 1] === 'u')
                {
                    commands.push('u');
                    i += 7;
                    continue;
                }
                else if (textForProcessing[i + 1] === 'm')
                {
                    commands.push('m');
                    i += 8;
                    continue;
                }
                else if (textForProcessing[i + 1] === '/')
                {
                    if (textForProcessing[i + 2] === 'l')
                    {
                        commands.pop();
                        i += 9;
                        continue;
                    }
                    else if (textForProcessing[i + 2] === 'u')
                    {
                        commands.pop();
                        i += 8;
                        continue;
                    }
                    else if (textForProcessing[i + 2] === 'm')
                    {
                        commands.pop();
                        i += 9;
                        continue;
                    }
                    else
                    {
                        return "Error in closing tag";
                    }
                }
                else
                {
                    return "Error in opening tag";
                }
            }

            if (commands[commands.length - 1] === 'u')
            {
                result.push(textForProcessing[i].toUpperCase());
            }
            else if (commands[commands.length - 1] === 'l')
            {
                result.push(textForProcessing[i].toLowerCase());
            }
            else if (commands[commands.length - 1] === 'm')
            {
                if ((Math.random() * 10) > 4)
                {
                    result.push(textForProcessing[i].toUpperCase());
                }
                else
                {
                    result.push(textForProcessing[i].toLowerCase());
                }
            }
            else
            {
                result.push(textForProcessing[i]);
            }
        }

        return result.join('');
    }

    var sampleText = "We are <mixcase>living</mixcase> in a <upcase>yellow submarine</upcase>. We <mixcase>don't</mixcase> have <lowcase>anything</lowcase> else.";
    console.log(parseToLowerUpperMix(sampleText));
    console.log("We are LiVinG in a YELLOW SUBMARINE. We dOn'T have anything else.");

    // for another algorithm
    function substringIndexer(inputString, substring)
    {
        var substringIndexes = [];
        var index = -1;

        do
        {
            index = inputString.toLowerCase().indexOf(substring.toLowerCase(), index + 1);

            if (index >= 0)
            {
                substringIndexes.push(index);
            }
        }
        while (index >= 0);

        return substringIndexes;
    }
}());